Skip to content

rush-resolver-cache-plugin: add pnpm 10 / lockfile v9 compatibility#5749

Open
bmiddha wants to merge 4 commits intomainfrom
bmiddha/resolver-cache-pnpm-10
Open

rush-resolver-cache-plugin: add pnpm 10 / lockfile v9 compatibility#5749
bmiddha wants to merge 4 commits intomainfrom
bmiddha/resolver-cache-pnpm-10

Conversation

@bmiddha
Copy link
Copy Markdown
Member

@bmiddha bmiddha commented Apr 7, 2026

Summary

add pnpm 10 / lockfile v9 compatibility to rush-resolver-cache-plugin

Details

rush-resolver-cache-plugin does not support v9 pnpm lockfile format
support pnpm lockfile format v9 and update tests for v6 and v9 format.

How it was tested

unit tests and manually tested integration with pnpm 10 repo.

Impacted documentation

@bmiddha bmiddha force-pushed the bmiddha/resolver-cache-pnpm-10 branch from 6034479 to 3ff472b Compare April 7, 2026 17:49
- Hoist regexes in depPathToFilename to module-level constants
- Unify v6/v9 branches in getDescriptionFileRootFromKey using offset
- Check specifier against packages list instead of regex heuristic
- Extract detectV9Lockfile helper (iterates with early return, no clone)
- Store version on IResolverContext when parsing lockfile keys
- Extract getStoreIndexPath helper in afterInstallAsync
- Use context.version instead of .split() on hot path
- Fix undefined in snapshot test names

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@dmichon-msft dmichon-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor things

const dir: string = `${pnpmStoreDir}${hashDir}/`;
const filePrefix: string = `${hashRest}-`;
try {
const files: string[] = readdirSync(dir);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use { withFileTypes: true } and only match files.

* or inspecting the first non-file package key.
*/
function detectV9Lockfile(lockfile: PnpmShrinkwrapFile): boolean {
const majorVersion: number | undefined = (lockfile as { shrinkwrapFileMajorVersion?: number })
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the lockfileVersion field not usable?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dropped support for pnpm 8

Comment on lines 207 to 218
if (!key.startsWith('file:')) {
const offset: number = key.startsWith('/') ? 1 : 0;
const versionAtIndex: number = key.indexOf('@', offset + 1);
if (versionAtIndex !== -1) {
if (!name) {
name = key.slice(offset, versionAtIndex);
}
const parenIndex: number = key.indexOf('(', versionAtIndex);
version =
parenIndex !== -1 ? key.slice(versionAtIndex + 1, parenIndex) : key.slice(versionAtIndex + 1);
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract this to its own helper and give it unit tests

return `${filename.substring(0, MAX_LENGTH_WITHOUT_HASH)}_${createBase32Hash(filename)}`;
export function depPathToFilename(depPath: string, usePnpm10Hashing?: boolean): string {
let filename: string = depPathToFilenameUnescaped(depPath).replace(SPECIAL_CHARS_REGEX, '+');
if (usePnpm10Hashing) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an @pnpm package we can import that is lightweight and does this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. i was avoiding it to avoid bringing in multiple versions of the package for v8 and v10 compat. i'll drop support for v8

bmiddha and others added 2 commits April 8, 2026 21:15
- Use readdirSync with { withFileTypes: true } to match only files
- Use lockfile.shrinkwrapFileMajorVersion directly (no cast needed)
- Extract extractNameAndVersionFromKey helper with unit tests
- Add comment explaining why depPathToFilename is inlined vs @pnpm/dependency-path

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add @pnpm/dependency-path as a dependency
- Remove custom depPathToFilename, createBase32Hash, createShortSha256Hash,
  depPathToFilenameUnescaped, and associated regex/hash constants
- Remove isV9Lockfile parameter from resolveDependencyKey/resolveDependencies
- Remove detectV9Lockfile helper (no longer needed)
- Remove unit tests for removed custom hash/filename functions
- Update snapshots to reflect pnpm 10 hashing

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs triage

Development

Successfully merging this pull request may close these issues.

2 participants